package com.ys.servers.points.data;

import com.ys.servers.common.data.DataEntity;
import com.ys.servers.common.util.TimeUtils;

/**
 * Created by taotao on 2017/5/8.
 */
public class PointsType extends DataEntity {

    private String title;

    private String desc;

    private String logDesc;

    public String getLogDesc() {
        return logDesc;
    }

    public PointsType setLogDesc(String logDesc) {
        this.logDesc = logDesc;
        return this;
    }

    //
    private PointsLoopType loopType;

    private LoopTypeUnit loopUnit;

    private int maxTime;

    //基本积分点数
    private int basicPoints = 0;

    //积分活动点数为  basicPoints+ incPointsTime*incBasicPoints*当前次数;
    private int incPointsTime = 0;

    private int incBasicPoints = 0;

    private int order;

    private int status = 0;

    public int getStatus() {
        return status;
    }

    public PointsType setStatus(int status) {
        this.status = status;
        return this;
    }

    public int getOrder() {
        return order;
    }

    public int getBasicPoints() {
        return basicPoints;
    }

    public PointsType setBasicPoints(int basicPoints) {
        this.basicPoints = basicPoints;
        return this;
    }

    public int getIncPointsTime() {
        return incPointsTime;
    }

    public PointsType setIncPointsTime(int incPointsTime) {
        this.incPointsTime = incPointsTime;
        return this;
    }

    public int getIncBasicPoints() {
        return incBasicPoints;
    }

    public PointsType setIncBasicPoints(int incBasicPoints) {
        this.incBasicPoints = incBasicPoints;
        return this;
    }

    public PointsType setOrder(int order) {
        this.order = order;
        return this;
    }

    public String getTitle() {
        return title;
    }

    public PointsType setTitle(String title) {
        this.title = title;
        return this;
    }

    public String getDesc() {
        return desc;
    }

    public PointsType setDesc(String desc) {
        this.desc = desc;
        return this;
    }

    public PointsLoopType getLoopType() {
        return loopType;
    }

    public PointsType setLoopType(PointsLoopType loopType) {
        this.loopType = loopType;
        return this;
    }

    public LoopTypeUnit getLoopUnit() {
        return loopUnit;
    }

    public PointsType setLoopUnit(LoopTypeUnit loopUnit) {
        this.loopUnit = loopUnit;
        return this;
    }

    public int getMaxTime() {
        return maxTime;
    }

    public PointsType setMaxTime(int maxTime) {
        this.maxTime = maxTime;
        return this;
    }

    @Override
    public double getScore() {
        return order;
    }

    @Deprecated
    public boolean shouldReset(long lastUpdateTime, int currentTimelyCount) {

        if (loopType.equals(PointsLoopType.TIME_LOOP)) {
            switch (loopUnit) {
                case DAILY_LOOP:
                    return !(TimeUtils.today(lastUpdateTime));
                case WEEKLY_LOOP:
                    return !(TimeUtils.thisWeek(lastUpdateTime));
                case MONTHLY_LOOP:
                    return !(TimeUtils.thisMonth(lastUpdateTime));
                default:
                    break;

            }
        } else if (loopType.equals(PointsLoopType.CONTINUOUS_LOOP)) {
            if (currentTimelyCount >= maxTime)
                return true;
            else if (TimeUtils.continuousDay(lastUpdateTime)) {
                return false;
            } else {
                return true;
            }
        }

        return false;
    }

    /**
     * @param lastUpdateTime     上一次获得积分时间
     * @param currentTimelyCount 当前重置后累计的获得次数（主要用于循环型积分获取）
     * @return
     */
    @Deprecated
    public int caculatePoint(long lastUpdateTime, int currentTimelyCount) {

        switch (loopType) {
            case NO_LOOP:
                return caculateNoLoopPoints(lastUpdateTime, currentTimelyCount);
            case TIME_LOOP:
                return caculateLoopPoints(lastUpdateTime, currentTimelyCount);
            case CONTINUOUS_LOOP:
                return caculateLoopPoints(lastUpdateTime, currentTimelyCount);
            default:
                break;
        }

        return 0;
    }

    /**
     * 不循环类型积分，例如：添加病程触发方式：添加病历并保存成功后（修改不算）类型：前5次触发
     *
     * @param lastUpdateTime
     * @param currentTimelyCount
     * @return
     */
    @Deprecated
    private int caculateNoLoopPoints(long lastUpdateTime, int currentTimelyCount) {
        if (currentTimelyCount < maxTime) {
            return caculatePoint(currentTimelyCount);
        }
        return 0;
    }
    @Deprecated
    private int caculateLoopPoints(long lastUpdateTime, int currentTimelyCount) {
        if (shouldReset(lastUpdateTime, currentTimelyCount)) {
            return caculatePoint(0);
        } else if (currentTimelyCount < maxTime) {
            return caculatePoint(currentTimelyCount);
        }
        return 0;
    }

    /*private int caculateContinuousPoints(long lastUpdateTime, int currentTimelyCount) {
        return 0;
    }*/

    public int caculatePoint(int times) {
        return basicPoints + incBasicPoints * incPointsTime * times;
    }



}
